<%@ page import="java.io.*"%>
<%@ page import="com.hline.kbcss.MyDriver"%>
<%@page import="java.sql.*"%>
<%
String username=(String)session.getAttribute("username");

System.out.println("+++++++++++++++"+username);
Object userid1=session.getAttribute("userid");
String userid2=userid1.toString();

int uid=Integer.parseInt(userid2);

System.out.println("+++++++++++++++"+uid);


String uname1=request.getParameter("uname1");
String gname1=request.getParameter("gname1");

System.out.println("+++++++++++++++"+uname1);



ResultSet rs3=null;
Statement stmt3=null;
try{
stmt3=MyDriver.getConnection("READ");
	String str3="SELECT * FROM user where username='"+uname1+"'";
rs3=stmt3.executeQuery(str3);
}catch(Exception e){
    System.out.println(""+e);
}
int id=0;
while(rs3.next()){

    id=rs3.getInt("userid");
}






ResultSet rs1=null;
Statement stmt1=null;
try{
stmt1=MyDriver.getConnection("READ");
	String str1="SELECT * FROM groups where gname='"+gname1+"' and userid="+uid ;
rs1=stmt1.executeQuery(str1);
}catch(Exception e){
    System.out.println(""+e);
}
int gid=0;
  while(rs1.next()){

	gid=rs1.getInt("gid");
	System.out.println("00000000000000000000"+gid);

}
		

	PreparedStatement pst=null;
	Statement st=null;
	ResultSet rs=null;
	

				
	st=MyDriver.getConnection("READ");
	
	pst=MyDriver.getPrepare("insert into groupdetails(userid,gid,gname,member,memberid) values(?,?,?,?,?)");
	System.out.println(" taking details ");
		
      try{      
            pst.setInt(1,uid);
			pst.setInt(2,gid);
			pst.setString(3,gname1);
			pst.setString(4, uname1);
			pst.setInt(5,id);
				
	System.out.println(" took values ");
         int i=pst.executeUpdate();
			
	
System.out.println("values inserted");
		
			 if(i>0)
			 {
	
				response.sendRedirect("abook.jsp?message=<font color=green>Added Successfully</font>");
				 
			 }
			 else
			 {
				 
				response.sendRedirect("abook.jsp?message=<font color=red> please try again</font>");
				 
			 }


}catch(Exception e){
			  System.out.println(e);
			  e.printStackTrace();
		  }
	
    

	%>
	
	
	